package com.example.yuekao.fragmenter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.bumptech.glide.Glide;
import com.example.mvp.Ui.Fragment.BaseMvpFragment;
import com.example.yuekao.R;
import com.example.yuekao.adapter.Adapter;
import com.example.yuekao.adapter.MyAdapter;
import com.example.yuekao.bean.Bean;
import com.example.yuekao.bean.Demo;
import com.example.yuekao.model.MianModel;
import com.example.yuekao.presenter.MainPresenter;
import com.example.yuekao.view.MianView;
import com.youth.banner.Banner;
import com.youth.banner.loader.ImageLoader;

import java.util.List;

public class OneFragment extends BaseMvpFragment<MianView, MianModel, MainPresenter> implements MianView {

    private Banner mBanner;
    private RecyclerView mRecyclerview;
    private RecyclerView recyclerView1;
    private ImageView mPanfang;
    private ImageView mJianshu;
    private ImageView mHangqing;
    private ImageView mYingshi;
    private RecyclerView mRecyclerview1;

    @Override
    protected void initEvent() {
        mPresenter.getData();

    }

    @Override
    protected MainPresenter createPresenter() {
        return new MainPresenter();
    }

    @Override
    protected int createLayoutId() {
        return R.layout.fragment_one;
    }

    @Override
    public void showList(List<Demo.ListBean> Demos) {
        mBanner = getActivity().findViewById(R.id.banner);
     //   recyclerView1 = getActivity().findViewById(R.id.recyclerView1);

        mBanner.setImages(Demos).setImageLoader(new ImageLoader() {
            @Override
            public void displayImage(Context context, Object path, ImageView imageView) {
                Demo.ListBean bean = (Demo.ListBean) path;
                Glide.with(context).load(bean.getThumb()).into(imageView);
            }
        }).start();
//        recyclerView1.setLayoutManager(new LinearLayoutManager(context));
//        Adapter adapter = new Adapter(Demos, context, R.layout.layout_rcy);
//        recyclerView1.setAdapter(adapter);


    }

    @Override
    public void showError(String error, int code) {

    }

    @Override
    public void onsuccessbean(List<Bean.ListBean> beans) {


        mBanner = getActivity().findViewById(R.id.banner);
//        mPanfang = getActivity().findViewById(R.id.panfang);
//        mJianshu = getActivity().findViewById(R.id.jianshu);
//        mHangqing = getActivity().findViewById(R.id.hangqing);
//        mYingshi = getActivity().findViewById(R.id.yingshi);
        mRecyclerview1 = getActivity().findViewById(R.id.recyclerView1);

//        Glide.with(context).load("https://img.zgsta.zhuge.com/news/0324/1616573385107601737.jpg").into(mPanfang);
//        Glide.with(context).load("https://img.zgsta.zhuge.com/news/0324/1616573408207577358.jpg").into(mJianshu);
//        Glide.with(context).load("http://img.zgsta.zhuge.com/news/1109/1604900139154450002.jpg").into(mHangqing);
//        Glide.with(context).load("http://img.zgsta.zhuge.com/news/0128/1611827917210722816.jpg").into(mYingshi);
        //  mRecyclerview = getActivity().findViewById(R.id.recyclerView);
       // mRecyclerview.setLayoutManager(new GridLayoutManager());
       // GridLayoutManager gridLayoutManager = new GridLayoutManager(this,3);

        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);

        mRecyclerview1.setLayoutManager(staggeredGridLayoutManager);

//
//        gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
//            @Override
//            public int getSpanSize(int position) {
//                if (position==0){
//                    return 3;
//                }
//                return 1;
//            }
//
//
//           });
        MyAdapter myAdapter = new MyAdapter(beans, context, R.layout.layout_item);
        mRecyclerview1.setAdapter(myAdapter);


    }

    @Override
    public void showProgressbar() {

    }

    @Override
    public void hideProgressbar() {

    }

    private void initViews(View view) {

    }
}